import React, { Component } from 'react'
import store from '../store'
import axios from 'axios'

export default class Count extends Component {
    add = () => {
        // store.dispatch({ type: "ADD" })
        // store.dispatch  ===>  经过中间件包装以后的dispatch
        store.dispatch((next) => {
            axios.get('/getNum').then(res => {
                // 当那到异步结果后  再发送给redux
                // store.dispatch 
                // next   最初的dispatch  
                next({ type: "ADD", res: res.data })
                this.setState({})
            })
        }) 
    }
    render() {
        const { getState } = store
        return (
            <div>
                <h3>
                    { getState().count }
                </h3>
                <button onClick={() => {
                    this.add()
                }}>+++</button>
            </div>
        )
    }
}
